# Makefile for the Era Astral project
# Use GCC (G++) for both compiling and linking on Linux
# Use MinGW for compiling and linking on windows
# Use GCC (G++) for both compiling and linking on OSX

# C++ compiler
CXX = g++
# C++ compiler flags
CXXFLAGS = -Wall `sdl-config --cflags` -D_GNU_SOURCE=1 -DHAVE_OPENGL -D_DEBUG -g
LINUXCXXFLAGS = -D_LINUX
WINCXXFLAGS = -D_WIN32 -Dmain=SDL_main
OSXCXXFLAGS = -D_OSX

# Linker
LD = g++
# Linker options
LINUXLDFLAGS = `sdl-config --libs` -lSDL_image -lGL -lGLU -lGLEW
WINDOWSLDFLAGS = `sdl-config --libs` -lSDL_image -lopengl32 -lglu32
OSXLDFLAGS = `sdl-config --libs` -lSDL_image -lGL -lGLU -lGLEW

# Remove command
RM = rm -f

# Name of final executable
LINUXPROG = EraAstral
WINPROG = EraAstral.exe
OSXPROG = EraAstral

# Primary sources
SOURCES = main.cpp BoundingObjects.cpp Camera.cpp CAmbientLight.cpp CAnimatedMesh.cpp CDirectionalLight.cpp \
	Color.cpp CPositionalLight.cpp CStaticMesh.cpp EventHandler.cpp FileHelpers.cpp \
	Game.cpp GameObject.cpp IDevice.cpp ILightSource.cpp IMesh.cpp InputDevice.cpp Logger.cpp MeshLoaders.cpp \
	SceneManager.cpp Sprite.cpp Texture.cpp TextureLoaders.cpp Timer.cpp Vector.cpp
# Sources for Linux build
LINUXSRC = CLinuxDevice.cpp LinuxHelpers.cpp
# Sources for Windows build
WINSRC = CWinDevice.cpp WindowsHelpers.cpp
# Sources for OSX build
OSXSRC = COSXDevice.cpp OSXHelpers.cpp

linux:
	$(CXX) $(CXXFLAGS) $(LINUXCXXFLAGS) -c $(SOURCES)
	$(CXX) $(CXXFLAGS) $(LINUXCXXFLAGS) -c $(LINUXSRC)
	
	$(LD) $(LINUXLDFLAGS) *.o -o $(LINUXPROG)
	
	mv *.o ./../obj/
	$(RM) ./../dist/Linux/$(LINUXPROG)
	mv $(LINUXPROG) ./../dist/Linux/
	
windows:
	$(CXX) $(CXXFLAGS) $(WINCXXFLAGS) -c $(SOURCES)
	$(CXX) $(CXXFLAGS) $(WINCXXFLAGS) -c $(WINSRC)
	
	$(LD) *.o -o $(WINPROG) $(WINDOWSLDFLAGS)
	
	mv *.o ./../obj/
	$(RM) ./../dist/Windows/$(WINPROG)
	mv $(WINPROG) ./../dist/Windows/

osx:
	$(CXX) $(CXXFLAGS) $(OSXCXXFLAGS) -c $(SOURCES)
	$(CXX) $(CXXFLAGS) $(OSXCXXFLAGS) -c $(OSXSRC)
	
	$(LD) $(OSXLDFLAGS) *.o -o $(OSXPROG)
	
	mv *.o ./../obj/
	$(RM) ./../dist/OSX/$(OSXPROG)
	mv $(OSXPROG) ./../dist/Linux/

clean:
	$(RM) $(LINUXPROG) $(WINPROG) $(OSXPROG) *.o ./../obj/*.o
